<?php
$this->Html->addCrumb('Users');
$this->Html->scriptStart(array('inline' => false));
echo '
      $(function(){
         $(".deleteLink").click(function(event){
          var $link = $(this);
          $.TWS_Overlay("confirm", {title : "Delete confirmation", message : "Are you sure you want to delete this record?", buttons : {ok :{onclick : function () { $.TWS_Overlay("hide"); location.href=$link.attr("href");}}}});
          event.preventDefault();
        });

        $(".displayContent").cluetip({splitTitle: "|", cluetipClass: "tws", dropShadow : false, positionBy : "mouse", cursor : "default"});
      });
       ';
$this->Html->scriptEnd();
?>

<h1>Users</h1>
<?php echo $this->Session->flash();?>

<? if (empty($users)) { echo '<p>No Users are currently available.</p>'; }
 else {
  ?>
   <table class="results" >
    <thead>
      <tr>
        <th width="20%"><?php echo $this->Paginator->sort('first_name','First Name')?></th>
        <th width="20%"><?php echo $this->Paginator->sort('last_name','Last Name')?></th>
        <th width="20%"><?php echo $this->Paginator->sort('email','Email')?></th>
        <th width="10%"><?php echo $this->Paginator->sort('active','Active')?></th>
        <th width="10%"><?php echo $this->Paginator->sort('verified','Verified')?></th>
        <th width="15%">Roles</th>
        <th width="15%">Actions</th>
      <tr>
   </thead>
   <tbody>
      <?php foreach ($users as $user) {
        $rec = $user['User'];
        $editLink = $this->Html->link('Edit', array('controller' => 'users', 'action' => 'edit', $rec['id']), array("title"=>"Edit this record"));
        $deleteLink = $this->Html->link('Delete', array('controller' => 'users', 'action' => 'delete', $rec['id']), array("title"=>"Delete this record", "class"=>'deleteLink'));
        //User roles
        $roles = array();
        foreach ($user['Role'] as $role){
          array_push($roles, $role['role_name']);
        }
        $modified = new DateTime($rec['modified']);
        echo '<tr>';
        echo '<td>'.$rec['first_name'].'</td>';
        echo '<td>'.$rec['last_name'].'</td>';
        echo '<td>'.$rec['email'].'</td>';
        echo '<td>'.$rec['active'].'</td>';
        echo '<td>'.$rec['verified'].'</td>';
        echo '<td>'.  implode(", ", $roles).'</td>';
        echo "<td>$editLink&nbsp;&nbsp;$deleteLink</td>";
        echo '</tr>';
      }?>
   </tbody>
   </table>

<?php echo $this->element('pagination'); ?>

 <?php } ?>

